const Controller = require('egg').Controller;

class HomeController extends Controller {
    async login() {
        const { ctx, app } = this;
        const data = await ctx.service.user.login()
        if (typeof data == 'string') {
            ctx.body = {
                code: -1,
                message: data
            }
        } else {
            ctx.body = {
                code: 1,
                message:'登录成功',
                data
            }
        }
    }

    ///注册
    async register() {
        const { ctx, app } = this;
        const data = await ctx.service.user.register()
        if (typeof data == 'string') {
            ctx.body = {
                code: -1,
                message: '注册失败'
            }
        } else {
            ctx.body = {
                code: 1,
                message: '注册成功'
            }
        }
    }
}

module.exports = HomeController;